1495B - Let's Go Hiking - CodeForces Solution


games greedy *1900

Please click on ads to support us..

C++ Code:

#include<unordered_map>
#include<functional>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<set>
#include<map>

#define fi first
#define se second
#define int long long
#define pii pair<int,int>
#define debug printf("++ ++\n");
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e5;
int n;
int a[N + 5];

signed main() {//首先一定是 波峰 其次波峰两边的下降长度相等 否则另一人可应变
	std::ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	int ri = 0, de = 0, timri = 0, timde = 0;
	for (int i = 1; i <= n; i++) {
		int l = i, r = i + 1;
		if (r <= n && a[r] > a[r - 1]) {
			while (r <= n && a[r] > a[r - 1]) r++;
			r--;
			if (r - l + 1 > ri) ri = r - l + 1, timri = 1;
			else if (r - l + 1 == ri) timri++;
		} else if (r <= n && a[r] < a[r - 1]) {
			while (r <= n && a[r] < a[r - 1]) r++;
			r--;
			if (r - l + 1 > de) de = r - l + 1, timde = 1;
			else if (r - l + 1 == de) timde++;
		}
		i = r - 1;
	}
	int tim = 0;
	for (int i = 2; i <= n - 1; i++) {
		if ((a[i] > a[i - 1] && a[i] > a[i + 1])) {
			int pl = i - 1, pr = i + 1;
			while (pl >= 1 && a[pl] < a[pl + 1]) pl--;
			pl++;
			while (pr <= n && a[pr] < a[pr - 1]) pr++;
			pr--;
			if (pr - i + 1 == i - pl + 1 && i - pl + 1 == ri && ri == de) tim++;
		}
	}
	if (tim == 1 && (ri & 1) && timri == timde && timri == 1) cout << "1\n";
	else cout << "0\n";
	return 0;
}
  		 	   						 		      	     	


Comments

Submit
0 Comments
More Questions

1029B - Creating the Contest
1421A - XORwice
1029A - Many Equal Substrings
1675D - Vertical Paths
1271C - Shawarma Tent
805A - Fake NP
1163A - Eating Soup
787A - The Monster
807A - Is it rated
1096A - Find Divisible
1430C - Numbers on Whiteboard
1697B - Promo
208D - Prizes Prizes more Prizes
659A - Round House
1492C - Maximum width
171B - Star
1512B - Almost Rectangle
831B - Keyboard Layouts
814A - An abandoned sentiment from past
268C - Beautiful Sets of Points
1391C - Cyclic Permutations
11A - Increasing Sequence
1406A - Subset Mex
1365F - Swaps Again
50B - Choosing Symbol Pairs
1719A - Chip Game
454B - Little Pony and Sort by Shift
1152A - Neko Finds Grapes
1719B - Mathematical Circus
1719C - Fighting Tournament